package alkaid.eis.sys.service;

import java.util.Set;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;

import org.springframework.data.jpa.domain.Specification;

import alkaid.eis.sys.entity.DictDetail;
import lombok.experimental.UtilityClass;

/**
 * 字典明细查询条件
 * 
 * @author Lucky Yang
 * @since 0.0.1
 */
@UtilityClass
public class DictDetailSpecifications {
    public Specification<DictDetail> empty() {
        return (Root<DictDetail> root, CriteriaQuery<?> query, CriteriaBuilder cb) -> {
            return null;
        };
    }

    public Specification<DictDetail> dictCodeIn(Set<String> dictCodes) {
        return (Root<DictDetail> root, CriteriaQuery<?> query, CriteriaBuilder cb) -> {
            return cb.in(root.get("dict").get("code")).value(dictCodes);
        };
    } 

    public Specification<DictDetail> codeIn(Set<String> codes) {
        return (Root<DictDetail> root, CriteriaQuery<?> query, CriteriaBuilder cb) -> {
            return cb.in(root.get("code")).value(codes);
        };
    }

    public static Specification<DictDetail> enabled(Boolean enabled) {
        return (Root<DictDetail> root, CriteriaQuery<?> query, CriteriaBuilder cb) -> {
            return cb.equal(root.get("enabled"), enabled);
        };
    }

    public static Specification<DictDetail> dictIdEqual(String dictId) {
        return (Root<DictDetail> root, CriteriaQuery<?> query, CriteriaBuilder cb) -> {
            return cb.equal(root.get("dict").get("id"), dictId);
        };
    }

    public static Specification<DictDetail> codeEqual(String code) {
        return (Root<DictDetail> root, CriteriaQuery<?> query, CriteriaBuilder cb) -> {
            return cb.equal(root.get("code"), code);
        };
    }    
}
